package com.shopping_back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopping_back.pojo.entity.GroupbuyItem;
import com.shopping_back.pojo.vo.GroupbuyDetailVO;
import com.shopping_back.pojo.vo.SkuItemVO;
import com.shopping_back.pojo.vo.SkuVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GroupbuyItemMapper extends BaseMapper<GroupbuyItem> {
    @Select("""
        SELECT  a.id                 AS activityId,
                a.name               AS activityName,
                a.start_time         AS startTime,
                a.end_time           AS endTime,
                a.status             AS status,
                i.group_price        AS groupPrice,
                i.required_count     AS requiredCount,
                i.duration_minutes   AS durationMinutes,
                s.id                 AS skuId,
                s.price              AS originalPrice,
                s.stock              AS stock,
                s.sku_image          AS skuImage,
                spu.title            AS spuTitle
        FROM promotion_activity a
        JOIN groupbuy_item     i   ON i.activity_id = a.id
        JOIN sku               s   ON s.id         = i.sku_id
        JOIN spu               spu ON spu.id       = s.spu_id
        WHERE a.id = #{activityId} AND a.type = '2'
    """)
    List<GroupbuyDetailVO> selectDetails(Long activityId);

    @Select("SELECT s.id AS sku_id, s.spu_id, sp.title AS spu_title, s.specs_json, s.price, s.stock, s.sku_image, " +
            "NULL AS seckill_price, NULL AS seckill_stock, NULL AS limit_per_user, " +
            "gi.group_price, gi.required_count, gi.duration_minutes, " +
            "NULL AS threshold, NULL AS discount, NULL AS combo_price " +
            "FROM groupbuy_item gi " +
            "JOIN sku s ON gi.sku_id = s.id " +
            "JOIN spu sp ON s.spu_id = sp.id " +
            "WHERE gi.activity_id = #{activityId}")
    List<SkuItemVO> selectGroupbuyItems(Long activityId);
}
